package com.rupertjones.globalcron.common.domain;

import com.rupertjones.globalcron.common.audit.Auditable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import static java.lang.String.format;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Entity
@Table(name = "role")
public class Role extends BaseEntity implements Auditable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    @Column
    private String name;

    @Override
    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int getId() {
        return this.id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toAuditLog() {
        return format("[id: %s] [name: %s]", id, name);
    }

    @Override
    public AuditLogType getAuditTypeForUpdate() {
        return AuditLogType.EDIT_ROLE;
    }

    @Override
    public AuditLogType getAuditTypeForInsert() {
        return AuditLogType.ADD_ROLE;
    }
}
